package com.mall.hadoop.job.allpeoplestatistics;

import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import com.mall.manager.service.AllPeopleStatisticsService;

public class AllPeopleMap extends Mapper<LongWritable, Text, Text, IntWritable>{

	@Override
	protected void map(LongWritable key, Text value, Context context)
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		String line = value.toString();
		String[] vs = line.split(",");
		String type = vs[0];
		int sum = Integer.parseInt(vs[1]);
		int babynum = 0;
		int schoolnum = 0;
		int teachernum = 0;
		if (type.equals("baby")) {
			babynum = sum;
			AllPeopleStatisticsService.manager_insert_allpeople(0, 0, babynum);
		}if (type.equals("class")) {
			teachernum = sum;
			AllPeopleStatisticsService.manager_update_allpeople(0, teachernum, 0);
		}if (type.equals("school")) {
			schoolnum = sum;
			AllPeopleStatisticsService.manager_update_allpeople(schoolnum, 0, 0);
		}
	}
}
